<template>
  <div class="about">
    <el-header>
      <div class="top">
        <img src="/康.jpg" alt />

        <div>
          <h3>后台管理系统</h3>
        </div>
      </div>

      <el-button type="info" @click="tui">退出</el-button>
    </el-header>

    <!-- 侧边导航 -->
    <el-row class="tac" :width="show?'80px':'200px'">
      <el-col :span="3">
        <el-menu
        :collapse="show"
         router
          :default-active="to"
          class="el-menu-vertical-demo"
          @open="handleOpen"
          @close="handleClose"
          background-color="#545c64"
          text-color="#fff"
          active-text-color="#ffd04b"
        >
          <span class="tu" @click="tu">||</span>
          <el-submenu v-for="item in list" :key="item.id" :index="item.path">
            <template slot="title">
              <i :class="icon[item.id]"></i>
              <span>{{item.authName}}</span>
            </template>

            <el-menu-item @click="toHandel('/'+items.path)" :index="'/'+items.path" v-for="items in item.children" :key="items.id">
              <i class="el-icon-menu"></i>

              <span>{{items.authName}}</span>
            </el-menu-item>
          </el-submenu>
        </el-menu>
      </el-col>
      <!-- 主体 -->
      <el-main>
        <router-view></router-view>
      </el-main>
    </el-row>
  </div>
</template>

<script>
// import { menu } from "../http/api";
export default {
  data() {
    return {
      to:"",
      list: [],
      icon: {
        125: "el-icon-user-solid",
        103: "el-icon-warning",
        101: "el-icon-s-goods",
        102: "el-icon-s-order",
        145: "el-icon-loading"
      },
      show: false
    };
  },
  // created() {
  //   menu().then(res => {
  //     this.list = res.data.data;
  //   });
  // },
  mounted() {
    this.$axios.get("menus").then(res => {
      this.list = res.data.data;
      // console.log(res);
      this.$message({
        message: res.data.meta.msg,
        type: "success"
      });
    });
  },
  created(){
this.to=localStorage.getItem("getto")
  },
  methods: {
    toHandel(val){
localStorage.setItem('getto',val)
this.to=val
      
    },
    tui() {
      this.$router.push("/login");
      localStorage.removeItem("token");
    },
    handleOpen(key, keyPath) {
      console.log(key, keyPath);
    },
    handleClose(key, keyPath) {
      console.log(key, keyPath);
    },
    tu() {
      this.show = !this.show;
      console.log(this.show);
    }
  }
};
</script>

<style lang="scss" scoped>
.about{
  width: 100%;
  height: 100%;
  background:#F3F3F9 ;
}
.el-main{
  width: auto;
height: calc(100vh - 60px);
  background: #d4d4d4;
}
.tu{
  margin-left: 28px;
  color: whitesmoke;
  cursor: pointer;
}
.el-menu-vertical-demo {
  height: calc(100vh - 60px);

}
.el-header {
  display: flex;
  align-items: center;
  // align-content: center;
  color: rgb(255, 255, 255);
  background: #545c64;
}
.top {
  display: flex;
  flex: 6;
  align-items: center;
  // align-content: center;
  justify-content: flex-start;
  img {
    width: 60px;
    height: 60px;
    margin-right: 20px;
    border-radius: 50px;
  }
}
</style>
